package com.ychs.controller;

import com.mysql.cj.xdevapi.JsonArray;
import com.ychs.bean.User;
import com.ychs.service.IUserService;
import net.sf.json.JSON;
import net.sf.json.JSONObject;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.PrintWriter;


/**
 * Description: 描述【】
 * Copyright: Copyright (c) 2018
 * Company: 英才汇硕信息技术有限公司
 *
 * @author tianchuanjie
 * @version 1.0
 * @created 2019/2/15 16:08
 */
@Controller
public class abca {

    Logger logger = Logger.getLogger(this.getClass());

    @Autowired
    IUserService userService;

    @GetMapping("we")
    public String ae() {
        return "front/abc";
    }

    @PostMapping("/abc")
    @ResponseBody //使用这个注解表示返回json数据
    public String abc(String username) {
        logger.debug(username);

        User user = userService.queryUserStatus(username);
        PrintWriter out = null;
        if (user != null) {
            logger.debug("存在");
            JSONObject jsonObject = JSONObject.fromObject(user);
            String json = jsonObject.toString();
            logger.debug(json);
            return json;
        } else {
            logger.debug("不存在");
            JSONObject object = new JSONObject();
           // object.put("nei", "改用户不存在");
            String json = object.toString();
            logger.debug(json);
            return json;
        }
    }

}
